﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ApplicationModels;

namespace IceDog.DNC.Web.Swashbuckle1_X.Convention
{
    /// <summary>
    /// 仅仅显示Get请求的请求行为约定
    /// </summary>
    public class ApiExplorerGetsOnlyConvention: IActionModelConvention
    {
        /// <summary>
        /// Called to apply the convention to the <see cref="T:Microsoft.AspNetCore.Mvc.ApplicationModels.ActionModel" />.
        /// </summary>
        /// <param name="action">The <see cref="T:Microsoft.AspNetCore.Mvc.ApplicationModels.ActionModel" />.</param>
        public void Apply(ActionModel action)
        {
            action.ApiExplorer.IsVisible = action.Attributes.OfType<HttpGetAttribute>().Any();
        }
    }
}
